// DAY
var day = new Date().getDate();

// MONTH
var numberOfMonth = new Date();
var monthName = new Array(11);
monthName[0]="January"; monthName[1]="February"; monthName[2]="March"; monthName[3]="April"; monthName[4]="May"; monthName[5]="June";
monthName[6]="July"; monthName[7]="August"; monthName[8]="September"; monthName[9]="October"; monthName[10]="November"; monthName[11]="December";
var month = monthName[numberOfMonth.getMonth()];

// YEAR
var year = new Date().getFullYear();

// HOUR
var hours = new Date().getHours();
var am_pm = 'AM';
	if(hours < 12){ am_pm = 'AM'; }else{ am_pm = 'PM'; }
	if(hours > 12){ hours = hours - 12; }
var minutes = new Date().getMinutes();

// DAY OF WEEK
var numberOfday = new Date();
var weekDay = new Array(7);
weekDay[0]="Sunday"; weekDay[1]="Monday"; weekDay[2]="Tuesday"; weekDay[3]="Wednesday"; weekDay[4]="Thursday"; 
weekDay[5]="Friday"; weekDay[6]="Saturday";
var shortWeekDay = new Array(7);
shortWeekDay[0]="Sun"; shortWeekDay[1]="Mon"; shortWeekDay[2]="Tue"; shortWeekDay[3]="Wed"; shortWeekDay[4]="Thu"; 
shortWeekDay[5]="Fri"; shortWeekDay[6]="Sat";
var dayOfWeek = weekDay[numberOfday.getDay()];

// MONTH DAYS
var monthDays = new Date(0).getDate();

// BEGIN DAY
var numberOfBDay = new Date();
numberOfBDay.setFullYear(year);
var thisMonth = new Date().getMonth(); 
numberOfBDay.setMonth(thisMonth);
numberOfBDay.setDate(1);
var beginDay = weekDay[numberOfBDay.getDay()];

// OTHER VARIABLES
var classType;

// CHANGE VALUES DEPENDING OF REQUIREMENT
var requestMonth = numberOfMonth.getMonth();
// Previous Month
function prevMonth() {
	// month
	if(requestMonth > 0){ requestMonth = requestMonth - 1; }else{ requestMonth = 11; }
	month = monthName[requestMonth];
	// year
	if(requestMonth == 11){ year = year - 1; }
	// month days
	rMonthDays = new Date(year, requestMonth + 1, 0).getDate();
	monthDays = rMonthDays;
	// begin day
	numberOfBDay.setFullYear(year);
	numberOfBDay.setMonth(requestMonth);
	numberOfBDay.setDate(1);
	beginDay = weekDay[numberOfBDay.getDay()];
	//printCalendar
	printCalendar();
}
// Next Month
function nextMonth() {
	// month
	if(requestMonth < 11){ requestMonth = requestMonth + 1; }else{ requestMonth = 0; }
	month = monthName[requestMonth];
	// year
	if(requestMonth == 0){ year = year + 1; }
	// month days
	rMonthDays = new Date(year, requestMonth + 1, 0).getDate();
	monthDays = rMonthDays;
	// begin day
	numberOfBDay.setFullYear(year);
	numberOfBDay.setMonth(requestMonth);
	numberOfBDay.setDate(1);
	beginDay = weekDay[numberOfBDay.getDay()];
	//printCalendar
	printCalendar();
}
// BEGIN CALENDAR TABLE
function beginCalendarTable(store){
	//var calendarTable ='<tr><td colspan="'+monthDays+1+'" align="center">'+month+" "+year+'</td></tr>';
	var calendarTable ='<tr><td colspan="'+monthDays+1+'" align="center">'+store+'</td></tr>';
	$("#"+store+" #calendar_"+store).append(calendarTable);
}
// PRINT CALENDAR DAYS
function printCalendarDays(store){
	// Create the calendar
	var calendarDaysWeek = '';
	// Set beginning day of week
	var beginerDay = 0;
	if(beginDay == "Sunday"){ beginerDay = 0; }
	else if(beginDay == "Monday"){ beginerDay = 1; }
	else if(beginDay == "Tuesday"){ beginerDay = 2; }
	else if(beginDay == "Wednesday"){ beginerDay = 3; }
	else if(beginDay == "Thursday"){ beginerDay = 4; }
	else if(beginDay == "Friday"){ beginerDay = 5; }
	else if(beginDay == "Saturday"){ beginerDay = 6; }
	// Insert days of week
	var calendarDaysWeek = '';
	for(n=1; n<=monthDays; n++){
	  calendarDaysWeek+='<td style="vertical-align:middle; text-align:center; width:20px; height:20px; display:table-cell; font-size:10px;">'+shortWeekDay[beginerDay]+'</td>';
	  if(beginerDay == 6){
	    beginerDay = 0;
	  }else{
	    beginerDay = beginerDay + 1;
	  }
	}
	// Print the calendar
	var calendar ='<tr><td style="vertical-align:middle; text-align:center; width:60px; height:20px; display:table-cell;"></td>'+calendarDaysWeek+'</tr>';
	$("#"+store+" #calendar_"+store).append(calendar);
}
// PRINT CALENDAR DATES
function printCalendarDates(id, store){
	// Create the calendars
	var calendarDays = '';
	// Insert days numbers
	for(n=1; n<=monthDays; n++){
	  calendarDays+='<td id="'+id+n+'" style="vertical-align:middle; text-align:center; width:20px; height:20px; display:table-cell;">'+n+'</td>';
	}
	// Print the calendar
	var calendar='<tr><td style="vertical-align:middle; text-align:center; width:60px; height:20px; display:table-cell;">'+id+'</td>'+calendarDays+'</tr>';
	$("#"+store+" #calendar_"+store).append(calendar);
}

// SET VARIABLES FOR MOUSE POSITION
var posX = 0;
var poxY = 0;
// SET VARIABLES FOR ACTIVE INPUTS AND TYPE OF DATE
var activeInput = '';
var typeOfDate = 1;
// GET MOUSE POSITION
$(document).mousemove(function(e){
	posX = e.pageX;
    posY = e.pageY;
});
// SHOW CALENDAR
function showCalendar(tag, typeDate) {
	$("#fdDivVolatil").fadeIn();
	$("#calendar").css({ 'display': 'block' });
	activeInput = tag;
	typeOfDate = typeDate;
}
// SET VALUE TO ACTIVE INPUT
function setValue(date) {
	if(typeOfDate == 1){
		var finalValue = date+"/"+(numberOfMonth.getMonth()+1)+"/"+year+" "+(hours<10?'0':'')+hours+":"+(minutes<10?'0':'')+minutes+" "+am_pm;
	}else if(typeOfDate == 2){
		var finalValue = date+"/"+(numberOfMonth.getMonth()+1)+"/"+year;
	}
	$("."+activeInput).val(finalValue);
	$("#calendar").hide();
	$("#fdDivVolatil").hide();
}